<?php
    use User\Model\ApplicationsModel;
?>
<style>
    .table>thead>tr>th{text-align: center;}
    .table>tbody>tr>td{vertical-align: middle; text-align: center; border-top:0}
    .btn-custom{color:white} .btn-custom:hover{color:white}
    .color1{background-color:#999933} .color2{background-color:#5CB85C} .color3{background-color:#D9534F}
    .color4{background-color:#F0AD4E}
</style>
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header">
                <span>用户 - {$nickname}</span>
            </h3>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <ul class="nav nav-tabs" id="myTab">
                        <li><a href="/User/Applications/comment">祝福列表</a></li>
                        <li><a href="/User/Applications/user">参加用户</a></li>
                        <li class="active">
                            <a href="/User/Applications/user_detail">
                                <if condition="$type eq ApplicationsModel::TYPE_SEND">已发出<else/>已收到</if>祝福
                            </a>
                        </li>
                        <li><a href="/User/Applications/statistics">数据统计</a></li>
                    </ul>

                </div>
                <div class="panel-body">
                    <div class="form-horizontal">
                        <div class="tab-content">
                            <div class="tab-pane active">
                                <a style="margin-left:15px" href="javascript:;" id="deleteAll" class="btn btn-custom color3">删除</a>
                                <div class="panel-body">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <th><input type="checkbox" id="selectAll"></th>
                                            <th>编号</th>
                                            <th>openid</th>
                                            <th>昵称</th>
                                            <th>祝福内容</th>
                                            <th>祝福方式</th>
                                            <th>创建时间</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <volist name="list" id="item">
                                            <tr>
                                                <td><input type="checkbox" name="ids" value="{$item.id}"></td>
                                                <td>{$item.id}</td>
                                                <td>{$item.openid}</td>
                                                <td>{$fans[$item["openid"]]}</td>
                                                <td>
                                                    <if condition="$item.comment_type eq ApplicationsModel::WISH_TXT">
                                                        {$item.content}
                                                        <else/>
                                                        <a href="javascript:;" onclick="showAudio('{$item[content]}');" class="btn btn-default" title="播放"><i class='fa fa-volume-up'></i> {$item.record_time}'</a>
                                                    </if>
                                                </td>
                                                <td>
                                                    <if condition="$item.comment_type eq ApplicationsModel::WISH_TXT">
                                                        <span class="label color1">文字</span>
                                                        <else/>
                                                        <span class="label color4">语音</span>
                                                    </if>
                                                </td>
                                                <td>{$item.createdate}</td>
                                                <td>
                                                    <a type="button" href="javascript:;" onclick="return deleteComment({$item['id']});" class="btn btn-custom color3">删除</a>
                                                </td>
                                            </tr>
                                        </volist>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="pages">
                                    {$page}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="music_player" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <audio id="audio_player" src="" controls="controls" style="width:100%"></audio>
        </div>
    </div>
</div>
<script>
    var audio = $("#audio_player")[0];
    $('#music_player').on('show.bs.modal', function () {
        audio.play();
    }).on('hide.bs.modal', function () {
        audio.pause();
    });

    function showAudio(content){
        $("#audio_player").attr("src", content);
        $('#music_player').modal("show");
    }

    function deleteComment(id){
        if(!confirm('确认删除吗？')) return false;
        $.ajax({
            data: {id: id},
            dataType: 'json',
            url: '/User/Applications/deleteComment',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }

    $("#selectAll").click(function(){
        if($(this).prop('checked') === true){
            $("input[name=ids]").prop('checked',true);
        }else{
            $("input[name=ids]").prop('checked',false);
        }
    });

    $("#deleteAll").click(function(){
        if(!confirm('确认删除吗？')) return false;
        var ids = "";
        $("input[name=ids]").each(function() {
            if($(this).prop("checked")){
                ids += $(this).val() + "|";
            }
        });
        if(ids !== ''){
            $.ajax({
                data: {ids: ids},
                dataType: 'json',
                url: '/User/Applications/deleteComments',
                type: 'get',
                success: function (res) {
                    alert(res['info']);
                    window.location.reload();
                }
            });
        }else{
            alert('请至少勾选一个祝福！');
        }
    });
</script>